package pingan.com.imandtwo.utils;

import okhttp3.OkHttpClient;
import pingan.com.imandtwo.interfaces.ApiServers;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by xsj on 2018/2/5.
 */

public class HttpUtils {

    private static  volatile  HttpUtils instance;
    private  ApiServers apiNet;

    public static HttpUtils getInstance() {
        if (instance == null) {
            synchronized (HttpUtils.class) {
                if (instance == null) {
                    instance = new HttpUtils();
                }
            }
        }
        return instance;
    }

    public HttpUtils() {
        Retrofit retrofit = new Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .baseUrl("http://www.bwstudent.com/")
                .client(new OkHttpClient.Builder().addInterceptor(new Logger()).build())
                .build();
        apiNet = retrofit.create(ApiServers.class);
    }

    public  ApiServers getapi(){
        return  apiNet;
    }

}
